<?PHP
 
// Config de Moodle, chemin à modifier en fonction du chemin d'installation de ce module
include('../../../config.php');
$SECURITE="OK";
include('../../includes/config/config.php');
include('../../includes/includes.php');

// Récupération de la structure
$id=$_POST['id'];
$nb=0;
  $tab_detail= "<table class='ui-widget ui-widget-content' style='font-size:13px;'>
  <thead class='ui-widget-header'><tr><th>Nom de l'étape Apog&eacute;</th><th>NB espaces</th><th>NB Etudiants</th><th>NB Enseignants</th></tr></thead>";
  //On prend toutes les structures
  $sql = "SELECT * FROM ".$CONF_bdd_prefixe."aua_structure WHERE C_STRUCTURE='".$id."'";
  $structs = mysql_query($sql);
  //Pour la structure on prend toutes les étapes
  $struct=mysql_fetch_object($structs);
    echo "<h2>".$struct->L_STRUCTURE."</h2>";
    $sql = "SELECT ".$CONF_bdd_prefixe."aua_etape.*,".$CONF_bdd_prefixe."aua_structure.L_STRUCTURE  
    FROM ".$CONF_bdd_prefixe."aua_etape,".$CONF_bdd_prefixe."aua_structure
    WHERE ".$CONF_bdd_prefixe."aua_etape.C_STRUCTURE=".$CONF_bdd_prefixe."aua_structure.C_STRUCTURE
    AND ".$CONF_bdd_prefixe."aua_etape.C_STRUCTURE='".$struct->C_STRUCTURE."'";
    //echo $sql."<br />";
    $etapes = mysql_query($sql);
    //Pour chaque étape on regarde les correspondances
    while($etape=mysql_fetch_object($etapes)){
      if(isset($etape->NO_ETAPE)){
        $sql = "SELECT count(id) as NB FROM ".$CONF_bdd_prefixe."correspondances WHERE id_type='3' AND code='2009".$etape->NO_ETAPE."'";
        $corresp = mysql_query($sql);                           
        //Pour chaque correspondances
        while($nb_corresp=mysql_fetch_object($corresp)){ 
          //On affiche que les correspondances qui ont un espace au moins
          if(isset($nb_corresp->NB) AND ($nb_corresp->NB!=0)){
            $nb+=$nb_corresp->NB;
            $sql="SELECT NO_ETUDIANT FROM ".$CONF_bdd_prefixe."aua_etudiant_etape WHERE NO_ANNEE=".$CONF_annee_en_cours." AND NO_ETAPE='".$etape->NO_ETAPE."'";
            $nb_etudiant_sql = mysql_query($sql);
            $nb_etudiant=mysql_num_rows($nb_etudiant_sql);
            $sql="SELECT NO_INDIVIDU FROM ".$CONF_bdd_prefixe."aua_personnel_etape WHERE NO_ANNEE=".$CONF_annee_en_cours." AND NO_ETAPE='".$etape->NO_ETAPE."'";
            $nb_enseignant_sql = mysql_query($sql);
            $nb_enseignant=mysql_num_rows($nb_enseignant_sql);
            
            $tab_detail.= "<tr><td>".$etape->L_ETAPE." (".$etape->NO_ETAPE.")</td><td>".$nb_corresp->NB."</td><td>".$nb_etudiant."</td><td>".$nb_enseignant."</td></tr>";                             
          }
        }
      }
    }
  
  $tab_detail.= "</table>";
  //echo $nb;  
  echo $tab_detail;
    
?>